const express = require("express")
const app = express()

const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

//封装res.send
// app.use((req,res,next) => {
//   res.output = function (err,status = 1,data = {}) {
//     res.send({
//       status,
//       message:err instanceof Error ? err.message:err,
//       data
//     })
//   }
//   next()
// })
// 使用 express-jwt 这个中间件，排除注册和登录
const {secretKey} = require("./config")
const { expressjwt: jwt } = require("express-jwt");
app.use(
    jwt({ secret: secretKey, algorithms: ["HS256"] }).unless({
      path: [/^\/user/],
    })
)

const {errorHandler} = require('./router_handler/error')
app.use(errorHandler)

const user = require("./router/login/user")
const info = require("./router/info/index")
// const checkin = require("./router/checkin/index")
// const social = require("./router/social/index")
app.use('/user',user)
app.use('/info',info)
// app.use("/check",checkin)
// app.use("/social",social)

app.listen(6011,() => {
    console.log("node server running");
})